//
//  UIImage+Extension.swift
//  WeiBoApp
//
//  Created by James on 2017/7/18.
//  Copyright © 2017年 James. All rights reserved.
//

import Foundation

extension UIImage {
    func hzj_avatarImage(size:CGSize?,backColor:UIColor = UIColor.white,lineColor:UIColor = UIColor.lightGray) -> UIImage? {
        var size = size
        if size == nil {
            size = self.size
        }
        
        let rect = CGRect(origin: CGPoint(), size: size!)
        
        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
        
        backColor.setFill()
        UIRectFill(rect)
        
        let path = UIBezierPath(ovalIn: rect)
        path.addClip()
        draw(in: rect)
        
        path.lineWidth = 2
        lineColor.setStroke()
        path.stroke()
        
        let result = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return  result
    }
}
